package com.hexiang.domain;

import javax.validation.GroupSequence;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import javax.validation.groups.Default;

import com.hexiang.First;
import com.hexiang.Second;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.validator.constraints.ScriptAssert;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ScriptAssert(script = "_this.startDay <= _this.endDay", lang = "javascript", message = "startDay必须小于或等于endDay")
@ScriptAssert(script = "parseInt((new Date(_this.endDay)-new Date(_this.startDay)) / (1000 * 60 * 60 * 24))<=30", lang = "javascript", message = "startDay和endDay时间不能超过30天")
public class QueryRequestDayStr {

    private static final String JAVASCRIPT_DATE_REG="(([2-9][0-9]|1[6-9])?[0-9]{2}([-\\/\\.])?((1[0-2]|0?[1-9])([-\\/\\.])?(2[0-8]|1[0-9]|0?[1-9])|(1[0-2]|0?[13-9])([-\\/\\.])?(29|30)|(1[02]|0?[13578])([-\\/\\.])?(31))|((1[6-9]|[2-9][0-9])?(0[48]|[2468][048]|[13579][26])|(16|[2468][048]|[3579][26])00)([-\\/\\.])?0?2([-\\/\\.])?(29))";

    @NotEmpty(message = "startDay不能为空")
    @Pattern(regexp = JAVASCRIPT_DATE_REG,message = "startDay格式不正确")
    private String startDay;

    @NotEmpty(message = "endDay不能为空",groups = {First.class})
    @Pattern(regexp = JAVASCRIPT_DATE_REG,message = "endDay格式不正确" )
    private String endDay;

    // 组序列
//    @GroupSequence({Default.class,First.class, Second.class})
//    public interface Group {
//    }
}